<?php

	/**
	 * File : move.php
	 * Description : Déplace un fichier sur le serveur
	 * Date : 07.08.2012 15:28:05
	 * 
	 * This file is part of Phenix.  Phenix is free software: you can
	 * redistribute it and/or modify it under the terms of the GNU General Public
	 * License as published by the Free Software Foundation, version 2.
	 *
	 * This program is distributed in the hope that it will be useful, but WITHOUT
	 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
	 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
	 * details.
	 *
	 * You should have received a copy of the GNU General Public License along with
	 * this program; if not, write to the Free Software Foundation, Inc., 51
	 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
	 *
	 * Nils Schaetti <n.schaetti@gmail.com>
	**/

	// En tête XML
	echo "<?xml version=\"1.0\"?>";

	// Includes
	require_once('core/libphenix.php');
	require_once('KTK/ktk.php');

	// Buffering
	ob_start();
	
	// Document type XML
	header("content-type: application/xml");

	// Démarre la session
	session_start();
	
	// Connexion à la base de données
	ktkConnectDB();
	
	// Vérifie le login
	if(!ktkCheckLogin())
	{
		echo '<files><error>Session expired</error></files>';
		exit;
	}

	// Connexion ssh
	if(($ssh_handler = lp_ssh_connect('localhost',$_SESSION['username'],$_SESSION['password'])) < 0)
	{
		echo "Impossible de se connecter via SSH";
		exit;
	}
	
	// Répertoire à bouger
	if(!isset($_GET['source']))
		$source = '.';
	else
		$source = $_GET['source'];
		
	// Répertoire destination
	if(!isset($_GET['destination']))
		$destination = '.';
	else
		$destination = $_GET['destination'];
		
	// Tag fichier
	echo '<files>';
		
	// Execute une commande
	if(lp_mv($ssh_handler,$source,$destination) === false)
	{
		echo "<error>You can't delete this file</error>";
	}
	
	// Ferme le tag fichier
	echo '</files>';
		
	// Ferme la connexion ssh
	lp_ssh_close($ssh_handler);	

	// Fin buffering
	ob_end_flush();

?>

